package cn.tedu._05mvcboot03.controller;

import cn.tedu._05mvcboot03.comment.response.JsonResult;
import cn.tedu._05mvcboot03.comment.response.StatusCode;
import cn.tedu._05mvcboot03.mapper.Mvc_userMapper;
import cn.tedu._05mvcboot03.pojo.DTO.UserLoginDTO;
import cn.tedu._05mvcboot03.pojo.entity.Mvc_user;
import cn.tedu._05mvcboot03.pojo.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;

@Api(tags = "用户模块")
@Slf4j
@Validated
@RestController
@RequestMapping("/v1/users/")
public class Mvc_userController {
    @Autowired
    public Mvc_userMapper mvcUserMapper;
    @PostMapping("login")
    @ApiOperation(value = "登录功能")
    public JsonResult login(@RequestBody UserLoginDTO userLoginDTO, @ApiIgnore HttpSession session){
        log.debug("userLoginDTO = " + userLoginDTO);
        UserVO userVO = mvcUserMapper.select(userLoginDTO.getUsername(),userLoginDTO.getPassword());
        if(userVO == null){
            return new JsonResult(StatusCode.USERNAME_PASSWORD_ERROR);
        }
        session.setAttribute("user",userVO);
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }
}
